package reflect;

import java.util.Scanner;

/**
 * 通过在控制台上输入一个类的完全限定名来实例化该类的实例
 *
 * 测试:
 * java.util.ArrayList
 * java.util.HashMap
 * reflect.Student
 * reflect.Teacher
 */
public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名:");
        Class cla = Class.forName(sc.nextLine());
        //使用公开且无参的构造器
        Object o = cla.newInstance();
        System.out.println(o.getClass().getName());
        System.out.println(o.getClass().getSimpleName());
        System.out.println(o.getClass().getPackage().getName());
    }
}
